package FIT::Fixture::Base;

use FIT::Class;
use aliased 'FIT::Document::Handler';

has table => ( # first table this fixture is handling
    is       => 'ro',
    isa      => 'XML::Twig::Elt',
    required => 1,
    handles  => {args => 'fixture_args', context => 'fit_context'},
);

sub do_tables {
    my $table = $self->table;
    $self->do_table($table);
    return $table->next_table;
}

sub do_table {
    my $table = shift;
    return unless $table->second_row;     # table with only 1 row
    $self->do_rows( $table->second_row ); # skip heading
}

sub do_rows {
    my $row = shift;
    do { $self->do_row($row) } while $row = $row->next_row;
}

sub do_row {
    my $row = shift;
    $self->do_cells( $row->first_cell );
}

sub do_cells {
    my $cell = shift;
    do { $self->do_cell($cell) } while $cell = $cell->next_cell;
}

sub do_cell { inner }

# document handler mechanism ---------------------------------------------------

Handler->add_handlers(__PACKAGE__);

my @COMMON_HANDLERS = qw(Skip Known ExpectedError);

sub table_handlers { @COMMON_HANDLERS }
sub row_handlers   { @COMMON_HANDLERS }
sub cell_handlers  { @COMMON_HANDLERS, qw(SameAsAbove Expression Product) }

